<?php

namespace ShowStop\UserBundle\Entity;


use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;

/**
 * ShowStop\UserBundle\Entity\User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 * @DoctrineAssert\UniqueEntity(fields={"username"}, message="This username has been taken." )
 * @DoctrineAssert\UniqueEntity(fields={"email"}, message="This email address has already been registered." )
 */
class User implements UserInterface
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $fname
     *
     * @ORM\Column(name="fname", type="string", length=20)
     * @Assert\MinLength(limit=2, message="Your first name must have at least {{ limit }} characters." )
     * @Assert\MaxLength(limit=20, message="Your first name must have at most {{ limit }} characters." )

     */
    private $fname;

    /**
     * @var string $lname
     *
     * @ORM\Column(name="lname", type="string", length=20)
     * @Assert\MinLength(limit=2, message="Your last name must have at least {{ limit }} characters." )
     * @Assert\MaxLength(limit=20, message="Your last name must have at most {{ limit }} characters." )

     */
    private $lname;

    /**
     * @var string $username
     *
     * @ORM\Column(name="username", type="string", length=50)
     */
    private $username;

    /**
     * @var string $password
     *
     * @ORM\Column(name="password", type="string", length=255)
     */
    private $password;

    /**
     * @var string $email
     * 
     * @Assert\Email(
     *     message = "The email '{{ value }}' is not a valid email."
     * )
     * @ORM\Column(name="email", type="string", length=6)
     */
    private $email;
    
    /**
    * @var string $salt
    *
    * @ORM\Column(name="salt", type="string", length=255)
    */
    private $salt;
    
    /**
    * @ORM\ManyToMany(targetEntity="Role", cascade={"persist"})
    * @ORM\JoinTable(name="user_role",
    *     joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
    *     inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
    * )
    *
    * @var ArrayCollection $userRoles
    */
    private $userRoles;
    
    /**
     * @ORM\ManyToMany(targetEntity="\ShowStop\TelevisionBundle\Entity\Series", cascade={"persist"})
     * @ORM\JoinTable(name="user_favorite",
     * 		joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
     * 		inverseJoinColumns={@ORM\JoinColumn(name="series_id", referencedColumnName="id")}
     * )
     * 
     * @var ArrayCollection $userFavorites
     */
    private $userFavorites;
    
    /**
    * @var string $gender
    *
    * @ORM\Column(name="gender", type="string", length=6)
    */
    private $gender;

    /**
     * @var integer $birth
     *
     * @ORM\Column(name="birth", type="integer")
     */
    private $birth;

    /**
     * @var string $status
     *
     * @ORM\Column(name="status", type="string", length=10)
     */
    private $status;

    /**
     * @var datetime $createdAt
     *
     * @ORM\Column(name="createdAt", type="datetime")
     */
    private $createdAt;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set fname
     *
     * @param string $fname
     */
    public function setFname($fname)
    {
        $this->fname = $fname;
    }

    /**
     * Get fname
     *
     * @return string 
     */
    public function getFname()
    {
        return $this->fname;
    }

    /**
     * Set lname
     *
     * @param string $lname
     */
    public function setLname($lname)
    {
        $this->lname = $lname;
    }

    /**
     * Get lname
     *
     * @return string 
     */
    public function getLname()
    {
        return $this->lname;
    }

    /**
     * Set user_name
     *
     * @param string $userName
     */
    public function setUsername($userName)
    {
        $this->username = $userName;
    }

    /**
     * Get user_name
     *
     * @return string 
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Set password
     *
     * @param string $password
     */
    public function setPassword($password)
    {
        $this->password = $password;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set email
     *
     * @param string $email
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }
    
    /**
    * Set gender
    *
    * @param string $gender
    */
    public function setGender($gender)
    {
    	$this->gender = $gender;
    }
    
    /**
    * Get gender
    *
    * @return string
    */
    public function getGender()
    {
    	return $this->gender;
    }

    /**
     * Set birth
     *
     * @param integer $birth
     */
    public function setBirth($birth)
    {
        $this->birth = $birth;
    }

    /**
     * Get birth
     *
     * @return integer 
     */
    public function getBirth()
    {
        return $this->birth;
    }

    /**
     * Set status
     *
     * @param string $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

    /**
     * Get status
     *
     * @return string 
     */
    public function getStatus()
    {
        return $this->status;
    }


    /**
     * Set $createdAt
     *
     * @param datetime $createdAt
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;
    }

    /**
     * Get createdAt
     *
     * @return datetime 
     */
    public function getDateCreated()
    {
        return $this->createdAt;
    }
    
/**
     * Gets the user salt.
     *
     * @return string The salt.
     */
    public function getSalt()
    {
        return $this->salt;
    }
 
    /**
     * Sets the user salt.
     *
     * @param string $value The salt.
     */
    public function setSalt($value)
    {
        $this->salt = $value;
    }
 
    /**
     * Gets the user roles.
     *
     * @return ArrayCollection A Doctrine ArrayCollection
     */
    public function getUserRoles()
    {
        return $this->userRoles;
    }
    
    /**
     * Gets the users favorite series
     * 
     * @return ArrayCollection A Doctrine ArrayCollection
     */
    public function getUserFavorites()
    {
    	return $this->userFavorites;
    }
    
    /**
     * Constructs a new instance of User
     */
    public function __construct()
    {
        $this->userRoles = new ArrayCollection();
        $this->userFavorites = new ArrayCollection();
        $this->createdAt = new \DateTime();
    }
 
    /**
     * Erases the user credentials.
     */
    public function eraseCredentials()
    {
 
    }
 
    /**
     * Gets an array of roles.
     * 
     * @return array An array of Role objects
     */
    public function getRoles()
    {
        return $this->getUserRoles()->toArray();
    }
 
    /**
     * Compares this user to another to determine if they are the same.
     * 
     * @param UserInterface $user The user
     * @return boolean True if equal, false othwerwise.
     */
    public function equals(UserInterface $user)
    {
        return md5($this->getUsername()) == md5($user->getUsername());
    }
}